import { defineStore } from "pinia";
import { GetNewMerchantInfo } from "@/api/merchant/index";
import { reactive } from "vue";
export const useMerchantStore = defineStore(
  "merchant",
  () => {
    let merchantInfo = reactive({
      login: 0,
      refund: 0,
      recharge: 0,
      pay: 0,
      withdraw: 0,
      kyc_manage: 0,
    });

    // 设置merchantInfo
    async function getMerchantInfo() {
      const res = await GetNewMerchantInfo();
      Object.assign(merchantInfo, {
        ...res.google_open,
        is_google_auth_open: res.is_google_auth_open,
        is_tradepwd: res.is_tradepwd,
        is_set_trade_password: res.is_set_trade_password,
      });
    }
    function setMerchantInfo(value, key, optValue) {
      merchantInfo[key] = value ? optValue : 0;
    }

    return { merchantInfo, getMerchantInfo, setMerchantInfo };
  },
  {
    persist: true,
  }
);
